package com.example.droolstest.util;

import org.kie.api.io.ResourceType;
import org.kie.api.runtime.KieSession;
import org.kie.internal.utils.KieHelper;

import java.util.Map;

public class DroolsUtil {
    /***
     * 执行规则
     * @param params
     * @param rule
     */
    public static void execute(Map<String, Object> params, String rule) {
        KieHelper helper = new KieHelper();
        helper.addContent(rule, ResourceType.DRL);
        KieSession kSession = helper.build().newKieSession();

        kSession.insert(params);
        kSession.fireAllRules();
        kSession.dispose();
    }

}
